define(['angularAMD'], function (angularAMD) {
    angularAMD.service('E06Service', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog',
        function($rootScope, $filter, $translate, config, $MMWService, $mdDialog){
            var _service = this;

            function position_collectMTL_lotset_process(content, callback){
                $MMWService.sendToServer({
                    uri: 'ServicesSTD.Module_SN.position_collectMTL_lotset_process',
                    content: content,
                    success: function (data) {
                        $rootScope.showToast($filter('translate')('common.msg.success'));
                        if(typeof(callback) == 'function')
                            callback();
                    }
                });
            }

            _service.LoadLotSet = function(data, callback){
                $MMWService.pageNumberInfoGet({
                    page_mode : 'position_collectMTL_lotset_get',
                    query_condition_info:[
                        {column_name:'a.PDLineNo', query_mode:'0', merge_condition_model:'AND', value:data.pdline_no },
                        {column_name:'a.OPNo', query_mode:'0', merge_condition_model:'AND', value:data.op_no },
                        {column_name:'a.PositionNo', query_mode:'0', merge_condition_model:'AND', value:data.position_no }
                    ]
                }, function(itemList){
                    if(typeof callback === 'function')
                        callback(itemList);
                });
            }

            _service.init = function(options){
                _service.LoadLotSet(options.stationMachine, function(itemList){
                    $mdDialog.dialog(
                        'module/moduleE/program/E06/E06.html',
                        function(dialog){
                            return {
                                css_url:'module/moduleE/program/E06/E06.css',
                                itemList:itemList,
                                beforeShown: function(){

                                },
                                back: function () {
                                    dialog.hide();
                                    if(options.close)
                                        options.close();
                                },
                                confirm: function () {
                                    position_collectMTL_lotset_process({collectMTL_lotset:dialog.itemList}, function(){
                                        if(typeof(options.callback) == "function")
                                            options.callback(dialog);
                                    });
                                }
                            };
                        }
                    );
                });

            };
        }]);
});
